package com.skycong.hello77.activity.listview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.skycong.hello77.R;

import java.util.List;

/**
 * Created by Kiki on 2018/6/1.
 */

public class TestListAdapter2 extends BaseAdapter {
    public List<String> dataList;
    public Context context;
    public LayoutInflater inflater;

    public TestListAdapter2(Context context, List<String> dataList){
        this.context = context;
        this.dataList = dataList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CityFormItem2 item = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_list2, null);
            item = new CityFormItem2(convertView);
            convertView.setTag(item);//绑定ViewHolder对象
        }
        else{
            item = (CityFormItem2)convertView.getTag();//取出ViewHolder对象
        }
        String str = dataList.get(position);
        item.setShow(str);
        return convertView;
    }

    public class CityFormItem2 extends RecyclerView.ViewHolder{
        public TextView tv_name2;
        public CityFormItem2(View view){
            super(view);
            tv_name2 = (TextView) view.findViewById(R.id.tv_name2);
        }
        public void setShow(String str){
            tv_name2.setText(str);
        }
    }
}

